//
//  CKMTViewController.m
//  CKMT
//
//  Created by Warren Holybee on 12/11/10.
//  Copyright 2010 Warren Holybee. All rights reserved.
//

#import "CKMTViewController.h"
#import "KOFYvideo.h"


@implementation CKMTViewController
@synthesize list;

-(IBAction)back: (id) sender {
	
	[[self parentViewController] dismissModalViewControllerAnimated:NO];
}

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	NSArray *array = [[NSArray alloc] initWithObjects:@"Welcome Back", @"The Killer Shrews",@"Voyage to the Planet of Prehistoric Woman",@"Teenagers from Outer Space",@"Wasp Women", nil];
    self.list = array;
	[array release];
	[super viewDidLoad];
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[list release];
    [super dealloc];
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
	return [self.list count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView
		cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *ckmtViewControllerCell = @"ckmtViewControllerCell";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ckmtViewControllerCell];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: ckmtViewControllerCell] autorelease];
	}
	NSUInteger row = [indexPath row];
	NSString *rowString = [list objectAtIndex:row];
	
	cell.textLabel.text = rowString;
	[rowString release];
	return cell;
	
	
	
}
/*
-(UITableViewCellAccessoryType)tableView:(UITableView *)tableView
		accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
	return UITableViewCellAccessoryDisclosureIndicator;
}
*/


-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	NSLog(@"row selected");
	// get text into NSString
	NSInteger c = [indexPath row];
	NSLog(@"c = %i",c);
	
	NSString *myURLString = [NSString stringWithFormat:@"http://r.unicornmedia.com/content.mp4?v=2067c8cc-ac8d-47eb-ad54-889b2d17615f&uid=1194dc9b-f0a4-4dcd-bb8d-a1a18031cb8b&at=cc6c67d7-a9fe-4435-adf6-97fe9b47bdf6&mediaitemprofileid=d0cf4520-b138-4356-9395-aa7477cf6144"];
	[myURLString retain];
	
	if (c == 0) // Welcome Back
	{
		[myURLString release];
		myURLString = [NSString stringWithFormat:@"http://r.unicornmedia.com/content.mp4?v=2067c8cc-ac8d-47eb-ad54-889b2d17615f&uid=1194dc9b-f0a4-4dcd-bb8d-a1a18031cb8b&at=cc6c67d7-a9fe-4435-adf6-97fe9b47bdf6&mediaitemprofileid=d0cf4520-b138-4356-9395-aa7477cf6144"];
		[myURLString retain];
		
		
	}
	
	if (c == 1) // The Killer Shrews
	{
		[myURLString release];
		myURLString = [NSString stringWithFormat:@"http://r.unicornmedia.com/content.mp4?v=2067c8cc-ac8d-47eb-ad54-889b2d17615f&uid=bac65d32-3d9d-4349-9078-e4d46880e65d&at=cc6c67d7-a9fe-4435-adf6-97fe9b47bdf6&mediaitemprofileid=d0cf4520-b138-4356-9395-aa7477cf6144"];
		[myURLString retain];
		
	}
	
	if (c == 2) // Prehistoric Woman
	{
		[myURLString release];
		myURLString = [NSString stringWithFormat:@"http://r.unicornmedia.com/content.mp4?v=2067c8cc-ac8d-47eb-ad54-889b2d17615f&uid=4645bce2-49df-4f56-b1cc-9ab174cb9fae&at=cc6c67d7-a9fe-4435-adf6-97fe9b47bdf6&mediaitemprofileid=d0cf4520-b138-4356-9395-aa7477cf6144"];
		[myURLString retain];
		
	}
	
	if (c == 3) // Teenagers
	{
		[myURLString release];
		myURLString = [NSString stringWithFormat:@"http://r.unicornmedia.com/content.mp4?v=2067c8cc-ac8d-47eb-ad54-889b2d17615f&uid=0518633c-41d2-4884-90f2-59fb8bd526ae&at=cc6c67d7-a9fe-4435-adf6-97fe9b47bdf6&mediaitemprofileid=d0cf4520-b138-4356-9395-aa7477cf6144"];
		[myURLString retain];
		
	}
	
	if (c == 4) // Wasp Woman
	{
		[myURLString release];
		myURLString = [NSString stringWithFormat:@"http://r.unicornmedia.com/content.mp4?v=2067c8cc-ac8d-47eb-ad54-889b2d17615f&uid=88cf2ffd-a092-421f-961d-caea8d866dc4&at=cc6c67d7-a9fe-4435-adf6-97fe9b47bdf6&mediaitemprofileid=d0cf4520-b138-4356-9395-aa7477cf6144"];
		[myURLString retain];
		
	}
	
	// create KOFYVideo object
	KOFYvideo *myKOFY = [[KOFYvideo	alloc] init];
	myKOFY.URLString = myURLString;
	myKOFY.view = self.view;
	[myKOFY playVideo];
	
	/*if (video == nil)
	 video = [[ckmtVideoController alloc] initWithNibName:@"ckmtVideo" bundle:nil];
	 video.title = @"CKMT";
	 
	 KOFYAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
	 [delegate.kofyController pushViewController:video animated:YES];
	 
	 
	 */
}

/*
-(void)tableView:(UITableView *)tableView
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
	
	 NSLog(@"accessory tapped");
	 if (video == nil)
	 video = [[ckmtVideoController alloc] initWithNibName:@"ckmtVideo" bundle:nil];
	 video.title = @"CKMT";
	 
	 KOFYAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
	 [delegate.kofyController pushViewController:video animated:YES];
	 
	 
}
*/

@end
